package org.xb.procedure_Oriented;

import java.util.Scanner;

/**
 * 这个是一个面向过程的计算器
 * 这样的面向过程的计算器没有什么扩展性  但是他的编写的速度相比于面向对象比较简单
 * 弊端就是不易扩展 违反了设计模式里面开闭合
 */
public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入数字1");
        String number1 = scanner.nextLine();
        System.out.println("请输入数字1");
        String number2 = scanner.nextLine();
        System.out.println("请选择运算符号（+、-、*、/）：");
        String operate = scanner.nextLine();
        Double result = null;
        switch (operate){
            case "+":
                result = Double.parseDouble(number1) + Double.parseDouble(number2);
                break;
            case "-":
                result = Double.parseDouble(number1) - Double.parseDouble(number2);
                break;
            case "*":
                result = Double.parseDouble(number1) * Double.parseDouble(number2);
                break;
            case "/":
                if (number2.equals("0")){
                    throw new RuntimeException("");
                }
                result = Double.parseDouble(number1) / Double.parseDouble(number2);
                break;
        }
        System.out.println("结果为" + result);
    }
}

